package com.ruoyi.business.service.impl;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.ruoyi.business.domain.Code;
import com.ruoyi.business.utils.SmsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.RepairReservationMapper;
import com.ruoyi.business.domain.RepairReservation;
import com.ruoyi.business.service.IRepairReservationService;



/**
 * 维修预约Service业务层处理
 * 
 * @author xjl
 * @date 2024-09-11
 */
@Service
public class RepairReservationServiceImpl implements IRepairReservationService 
{
    @Autowired
    private RepairReservationMapper repairReservationMapper;

    /**
     * 查询维修预约
     * 
     * @param id 维修预约主键
     * @return 维修预约
     */
    @Override
    public RepairReservation selectRepairReservationById(Long id)
    {
        return repairReservationMapper.selectRepairReservationById(id);
    }

    /**
     * 查询维修预约列表
     * 
     * @param repairReservation 维修预约
     * @return 维修预约
     */
    @Override
    public List<RepairReservation> selectRepairReservationList(RepairReservation repairReservation)
    {
        return repairReservationMapper.selectRepairReservationList(repairReservation);
    }

    /**
     * 新增维修预约
     * 
     * @param repairReservation 维修预约
     * @return 结果
     */
    @Override
    public int insertRepairReservation(RepairReservation repairReservation)
    {
        return repairReservationMapper.insertRepairReservation(repairReservation);
    }

    /**
     * 修改维修预约
     * 
     * @param repairReservation 维修预约
     * @return 结果
     */
    @Override
    public int updateRepairReservation(RepairReservation repairReservation)
    {
        /*如果维修状态改为2已完成，向用户发送短信*/
        if(repairReservation.getStatus()==2){
            SmsUtil.sendSms("19315521530", "阿里云短信测试", "SMS_154950909", JSON.toJSONString(new Code(6666)));
        }
        return repairReservationMapper.updateRepairReservation(repairReservation);
    }

    /**
     * 批量删除维修预约
     * 
     * @param ids 需要删除的维修预约主键
     * @return 结果
     */
    @Override
    public int deleteRepairReservationByIds(Long[] ids)
    {
        return repairReservationMapper.deleteRepairReservationByIds(ids);
    }

    /**
     * 删除维修预约信息
     * 
     * @param id 维修预约主键
     * @return 结果
     */
    @Override
    public int deleteRepairReservationById(Long id)
    {
        return repairReservationMapper.deleteRepairReservationById(id);
    }

    @Override
    public List<RepairReservation> getRepairTasksByStatusAndMethod(Long status, String type) {

        return repairReservationMapper.selectRepairTasksByStatusAndMethod(status,type);
    }

    @Override
    public RepairReservation getRepairTaskByOrderNumber(Long id) {
        return repairReservationMapper.selectRepairTaskById(id);
    }

    @Override
    public int updateRepairStatusById(RepairReservation repairReservation) {
        return repairReservationMapper.updateRepairTaskStatus(repairReservation);
    }

    @Override
    public int updateStatusById(RepairReservation repairReservation) {

        // 更新任务状态
        int updateRepair = repairReservationMapper.updateRepairTaskStatus2(repairReservation);
/*查询新状态*/

        // 如果维修状态改为 2（已完成），发送短信

            SmsUtil.sendSms("19315521530", "阿里云短信测试", "SMS_154950909", JSON.toJSONString(new Code(6666)));

        return updateRepair;
    }


}













